part of '../repository.dart';

const _kTimeMsKey = 'ms';

class _TimeDto extends Equatable {
  const _TimeDto._internal({
    required this.time,
  });

  final DateTime time;

  @override
  List<Object?> get props {
    return [
      time,
    ];
  }

  factory _TimeDto.fromJson(Map<String, dynamic> json) {
    final milliseconds = json[_kTimeMsKey] as int;

    final dateTime = DateTime.fromMillisecondsSinceEpoch(
      milliseconds,
      isUtc: true,
    );

    return _TimeDto._internal(
      time: dateTime,
    );
  }

  factory _TimeDto.fromEntity(DateTime time) {
    return _TimeDto._internal(
      time: time,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kTimeMsKey: time.millisecondsSinceEpoch,
    };
  }

  DateTime toEntity() {
    return time;
  }
}
